package com.ykq.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ykq.dao.EmpInfoMapper;
import com.ykq.entity.EmpInfo;
import com.ykq.service.EmpInfoService;
import com.ykq.vo.EmpSearchVo;
import com.ykq.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @program: qy174-mrcai
 * @description:
 * @author: 闫克起
 * @create: 2024-06-04 11:34
 **/
@Service
public class EmpInfoServiceImpl implements EmpInfoService {
    @Autowired
    private EmpInfoMapper empInfoMapper;

    @Autowired
    private HttpSession session;

    public R findByNameAndPwd(String username, String pwd) {
        EmpInfo empInfo = empInfoMapper.selectByNameAndPwd(username, pwd);
        if (empInfo == null) {
            return new R(5000, "账号或密码错误", null);
        }
        if (empInfo.getState().equals(1)) {
            return new R(5000, "该员工已离职", null);
        }
        if (empInfo.getState().equals(2)) {
            return new R(5000, "该员工已被冻结请联系管理员", null);
        }
        //把当前用户保存再session中
        session.setAttribute("empinfo", empInfo);
        return new R(2000, "登录成功", null);
    }

    public R selectByConditPage(Integer current, Integer pageSize, EmpSearchVo empSearchVo) {
        PageHelper.startPage(current, pageSize);
        List<EmpInfo> list = empInfoMapper.selectByCondition(empSearchVo);
        PageInfo<EmpInfo> pageInfo=new PageInfo<EmpInfo>(list);
        return new R(2000,"查询成功",pageInfo);
    }
}














